import thin_render from "./thin_render.mjs";
import render_content from "./render_content.mjs";
import viewmode from "./viewmode.mjs";

export default function formviewitem_template(container, template) {
  let field = document.createElement(Object.keys(template)[0]);
  container.appendChild(field);
  // field.style.setProperty("--colspan", template.colspan || 1);

  if (template.title !== undefined) {
    let label = document.createElement("label");
    field.appendChild(label);
    label.innerText = render_content(label, template.title);
  }

  // let viewmode = viewmode(field);

  if (template.insert !== undefined && viewmode(field) === "insert") {
    thin_render(field, template.insert);
  } else if (
    template.edit !== undefined &&
    (viewmode(field) === "edit" || viewmode(field) === "insert")
  ) {
    thin_render(field, template.edit);
  } else {
    thin_render(field, Object.values(template)[0]);
  }
}
